Mapping a sphere mesh into a superquadric

Metadata
aliases: []
shorthands: {}
created: 2022-02-28 15:48:42
modified: 2022-02-28 15:48:42

After generating a sphere mesh, we might want to transform it into a superquadric shape. This is easy to do using the inverse parametrization of superquadric, because we can just treat the sphere as a superquadric with and . Then after getting the coordinates, we can generate the superquadric.

This might be useful when we have a uniformly generated sphere, but we cannot do the same for a superquadric shape instead just use this mapping and the superquadric turns out fairly uniform.

Implementation

Written in Python. The sphere has to have a unit radius! The arguments:

import numpy as np

def r1_sphere_to_sq(x, y, z, a, b, c, n1=2., n2=2.):
    # Inverse parametrization
    u = np.arcsin(np.array(z))
    v = np.arctan2(np.array(y), np.array(x))

    exp1 = 2.0 / n1
    exp2 = 2.0 / n2

    # Then map (u, v) to the superquadric
    x_out = a * np.sign(np.cos(u)) * np.abs(np.cos(u)) ** exp1 * np.sign(np.cos(v)) * np.abs(np.cos(v)) ** exp2
    y_out = b * np.sign(np.cos(u)) * np.abs(np.cos(u)) ** exp1 * np.sign(np.sin(v)) * np.abs(np.sin(v)) ** exp2
    z_out = c * np.sign(np.sin(u)) * np.abs(np.sin(u)) ** exp1
    return x_out, y_out, z_out